document.addEventListener('DOMContentLoaded', () => {
    const loginForm = document.getElementById('loginForm');
    const loginMessage = document.getElementById('loginMessage');
    const loginButton = document.querySelector('.login-button');

    // 清除之前的登录状态
    localStorage.removeItem('isLoggedIn');

    loginForm.addEventListener('submit', async (e) => {
        e.preventDefault();
        
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;
        
        // 添加加载状态
        loginButton.classList.add('loading');
        loginMessage.className = 'login-message';
        loginMessage.textContent = '';

        // 模拟登录请求
        await new Promise(resolve => setTimeout(resolve, 1000));

        if (username === 'admin' && password === 'admin') {
            // 登录成功
            loginMessage.className = 'login-message success';
            loginMessage.textContent = '登录成功，正在跳转...';
            
            // 存储登录状态
            localStorage.setItem('isLoggedIn', 'true');
            
            // 延迟跳转
            setTimeout(() => {
                window.location.href = 'index.html';
            }, 1000);
        } else {
            // 登录失败
            loginMessage.className = 'login-message error';
            loginMessage.textContent = '用户名或密码错误';
            loginButton.classList.remove('loading');
            
            // 震动效果
            loginForm.classList.add('shake');
            setTimeout(() => {
                loginForm.classList.remove('shake');
            }, 500);
        }
    });
});

// 添加震动动画
const style = document.createElement('style');
style.textContent = `
    @keyframes shake {
        0%, 100% { transform: translateX(0); }
        25% { transform: translateX(-10px); }
        75% { transform: translateX(10px); }
    }
    
    .shake {
        animation: shake 0.5s ease-in-out;
    }
`;
document.head.appendChild(style); 